# -*- coding: utf-8 -*-            
# @Author : HJH
# @Time : 2024/3/18 16:44
# @Use : 黑屏请求接口汇总
import hashlib
import json
import uuid
from datetime import datetime

import requests


def send_pat_request(flight, dep, arr, cabin, dep_date, uid):
    data = {
        "account": "yucheng",
        "flightItem": [
            {
                "arr": arr,
                "cabin": cabin,
                "date": dep_date,
                "dep": dep,
                "flight": flight
            }
        ],
        "kEY": "0346b89b9153134d401c7f5f1446c3b3",
        "officeCode": "CGO104",
        "port": "352",
        "server": "121.40.73.220",
        "sessionid": uuid.uuid4().hex,
        "termid": "raw-pat-api-xtyd4",
        "uid": uid,
        "verify": 0
    }
    str_e = json.dumps(data).replace(" ", "") + "0346b89b9153134d401c7f5f1446c3b3"
    hex_str = hashlib.md5(str_e.encode())
    hex_str = hex_str.hexdigest()
    token = hex_str.lower()
    return requests.request("POST", f"http://aliapi.168380.com/api/Pat.ashx?Token={token}", data=json.dumps(data),
                            timeout=10000)


def send_avh_request(dep, arr, dep_date, ac_code, uid):
    # 日期格式转换
    dep_date = datetime.strptime(dep_date, "%Y-%m-%d").strftime("%d%m")

    data = {
        "account": "yucheng",
        "ins": f"AVH/{dep}{arr}/{dep_date}/0000/{ac_code}/D",
        "kEY": "0346b89b9153134d401c7f5f1446c3b3",
        "port": "352",
        "server": "121.40.73.220",
        "sessionid": "M7zqeuAj4Sk5PJ2ez5pyn",
        "termid": "raw-avh-api-xxt05",
        "uid": uid,
        "verify": 0
    }
    str_e = json.dumps(data).replace(" ", "") + "0346b89b9153134d401c7f5f1446c3b3"
    hex_str = hashlib.md5(str_e.encode())
    hex_str = hex_str.hexdigest()
    token = hex_str.lower()
    return requests.request("POST", f"http://aliapi.168380.com/api/Flight.ashx?Token={token}", data=json.dumps(data),
                            timeout=10000)
